﻿<!doctype html>
 <html >
 <head>
   <meta charset="UTF-8">
   <link rel="stylesheet" href="/css/common.css">
   <link rel="stylesheet" href="/css/main.css">
   <script type="text/javascript" src="/js/jquery.min.js"></script>
   <script type="text/javascript" src="/js/colResizable-1.3.min.js"></script>
   <script type="text/javascript" src="/js/common.js"></script>
</head>

<body>
<div id="forms" class="mt10">
      <div class="box">
          <div class="box_border">
            <div class="box_top"><b class="pl15">请假申请</b>
            </div>
            <div class="box_center">
              <form id="form" class="jqtransform">
                  <table class="form_table pt15 pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                          <td class="td_right">姓名：</td>
                          <td class="">
                              <input style="width: 40px; background-color: #EEEEEE;" readonly name="realName" value="${user.realName}">
                          </td>
                      </tr>
                      <tr>
                          <td class="td_right">部门：</td>
                          <td class="">
                              <select id="pp" style="width: 66px; background-color: #EEEEEE;" disabled="disabled" name="deptId">
                                  <#list dept as d>
                                      <option <#if d.deptId == user.deptId>
                                          selected
                                      </#if> value="${d.deptId}">${d.deptName}</option>
                                  </#list>
                              </select>
                          </td>
                      </tr>
                      <tr>
                          <td class="td_right">请假时间：</td>
                          <td>
                              <input id="start" type="date" name="startLeave" class="input-text lh30" size="40">
                              to
                              <input id="end" type="date" name="endLeave" class="input-text lh30" size="40">
                          </td>
                      </tr>
                      <tr>
                          <td class="td_right">请假天数：</td>
                          <td>
                              <input type="number" id="dayLeave" name="dayLeave" class="input-text lh30" size="40">
                          </td>
                      </tr>
                      <tr>
                          <td class="td_right">请假类型：</td>
                          <td>
                              <select id="qw" name="typeLeave" class="input-text lh30">
                                  <option value="-1">---请选择---</option>
                                  <#list leaveTypes as let>
                                      <option value="${let.leaveTypeId}">${let.leaveTypeName}</option>
                                  </#list>
                              </select>
                          </td>
                      </tr>
                      <tr>
                          <td class="td_right">请假事由：</td>
                          <td>
                              <textarea onchange="gai()" id="yuy" name="causeLeave" class="input-text lh30"></textarea>
                          </td>
                      </tr>
                      <tr>
                          <td>

                          </td>
                          <td>
                              <font color="red">说明:普通员工请假天数小于2天的,部门经理审批<br>
                                                3-5天的总监审批<br>大于5天的总经理审批<font>
                          </td></tr>
                      <tr>
                          <td class="td_right">下一步审批人：</td>
                          <td>
                              <select class="input-text lh30" name="userId" id="userid">
                                  <option value="-1">---请选择---</option>
                              </select>
                          </td>
                      </tr>
                      <tr>
                           <td class="td_right">&nbsp;</td>
                           <td class="">
                             <input type="button" id="tBtn" class="btn btn82 btn_save2" value="确定">
                             <input type="button" class="btn btn82 btn_res" onclick="location.href='javascript:history.go(-1)'" value="返回">
                           </td>
                      </tr>
               </table>
              </form>
            </div>
          </div>
      </div>
  </div>
<script>
    //输入框必须输汉字
    function gai(){
        if(!/^[\u4e00-\u9fa5]+$/gi.test(document.getElementById("yuy").value)){
            alert("必须输入汉字")
            return;
        }
    }
    //比较时间
    $("#end").change(function () {
        var start = $("#start").val().split("-");
        var starts = start[0] + start[1] + start[2];
        var end = $("#end").val().split("-");
        var ends = end[0] + end[1] + end[2];
        if (parseInt(ends) < parseInt(starts)){
            alert("输入错误，结束时间不能大于开始时间");
            location.href = "/leave/leave-ui";
        }
    });
    //添加请假
    $("#tBtn").click(function () {

        if(!/^[\u4e00-\u9fa5]+$/gi.test(document.getElementById("yuy").value)){
            alert("您还没有改成汉字，回去改正吧")
            return;
        }
        var qw = $("#qw").val();
        if (parseInt(qw) <= 0){
            alert("您还没有选择请假类型");
            return;
        }
        $("#pp").removeAttr("disabled");
        $.post(
            "/leave/add-leave"
            ,$("#form").serialize()
            ,function (result) {
                if (result.code == 0){
                    alert("申请请假已送达,等待审核，请耐心等待")
                    location.href = "/leave/leave-ui";
                } else {
                    alert(result.msg);
                }
            }
            ,"json"
        );
    });
    //联动天数和审核人
    // 说明:普通员工请假天数小于2天的,部门经理审批<br>
    // 3-5天的总监审批<br>大于5天的总经理审批
    $("#dayLeave").change(function () {
        var dayLeave = $("#dayLeave").val();
        if (parseInt(dayLeave) <= 0){
            alert("输入的值不合法！请重新输入。")
            location.href = "/leave/leave-ui";
            return;
        } 
        if (parseInt(dayLeave) <= 2){
            alert("部门经理审核");
            $.getJSON(
                "/leave/two-check-m"
                ,null
                ,function (result) {
                    if (result.code == 0){
                        //$("#userid")[0].add(new Option(result.data.realName,result.data.userId));
                        // 3. 插入.
                        $("#userid").html("<option value='" + result.data.userId + "'>" + result.data.realName + "</option>");
                    } else {
                        alert("失败了，吊哥");
                    }
                }
            );
            return;
        } 
        if (parseInt(dayLeave) <= 5){
            alert("总监审批");
            $.getJSON(
                "/leave/two-check-ci"
                ,null
                ,function (result) {
                    if (result.code == 0){
                        //$("#userid")[0].add(new Option(result.data.realName,result.data.userId));
                        // 3. 插入.
                        $("#userid").html("<option value='" + result.data.userId + "'>" + result.data.realName + "</option>");
                    } else {
                        alert("失败了，吊哥");
                    }
                }
            );
            return;
        } 
        if (parseInt(dayLeave) > 5){
            alert("总经理审批");
            $.getJSON(
                "/leave/two-check-gm"
                ,null
                ,function (result) {
                    if (result.code == 0){
                        //$("#userid")[0].add(new Option(result.data.realName,result.data.userId));
                        // 3. 插入.
                        $("#userid").html("<option value='" + result.data.userId + "'>" + result.data.realName + "</option>");
                    } else {
                        alert("失败了，吊哥");
                    }
                }
            );
            return;
        }
    });
    
    
    /*//异步获取用户名
    $.getJSON(
        "/user/get-username"
        ,null
        ,function (result) {
            if (result.code == 0){
                $("#username").html(result.data);
            } else {
                alert("您还未登录，重定向到登录页面")
                location.href = "/user/login-ui";
            }
        }
    );*/
</script>
</body>
</html>